/*
 * Copyright (c) 2018 Zhang Hai <Dreaming.in.Code.ZH@Gmail.com>
 * All Rights Reserved.
 */

package me.zhanghai.openharmony.materialplaypausedrawable;


import ohos.agp.components.AttrHelper;
import ohos.agp.components.Component;
import ohos.app.Context;
import ohos.global.resource.ResourceManager;

class ViewUtils {

    private ViewUtils() {
    }

    public static float vpToPx(float vp, Context context) {
        return AttrHelper.vp2px(vp, context);
    }

    public static int dpToPxOffset(float dp, Context context) {
        return (int) vpToPx(dp, context);
    }

    public static int vpToPxSize(float dp, Context context) {
        double value = vpToPx(dp, context);
        int size = (int) (value >= 0 ? value + 0.5 : value - 0.5);
        if (size != 0) {
            return size;
        } else if (value == 0) {
            return 0;
        } else if (value > 0) {
            return 1;
        } else {
            return -1;
        }
    }

    public static int getShortAnimTime(ResourceManager resources) {

        return 200;
    }

    public static int getShortAnimTime(Component view) {
        return getShortAnimTime(view.getResourceManager());
    }

    public static int getShortAnimTime(Context context) {
        return getShortAnimTime(context.getResourceManager());
    }

    public static int getMediumAnimTime(ResourceManager resources) {
        return 400;
    }

    public static int getMediumAnimTime(Component view) {
        return getMediumAnimTime(view.getResourceManager());
    }

    public static int getMediumAnimTime(Context context) {
        return getMediumAnimTime(context.getResourceManager());
    }

    public static int getLongAnimTime(ResourceManager resources) {
        return 500;
    }

    public static int getLongAnimTime(Component view) {
        return getLongAnimTime(view.getResourceManager());
    }

    public static int getLongAnimTime(Context context) {
        return getLongAnimTime(context.getResourceManager());
    }
}
